package command;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

/**
 * @author Jeff Zhuo
 *
 */
public class PropertiesUtil {

	/**
	 * Get the Properties by location
	 * @param location
	 * @return 
	 */
	public static Properties getProperties(String location) {
		Properties prop = null;
		try {
			prop = new Properties();
			InputStream is = new FileInputStream(PropertiesUtil.class.getClassLoader().getResource("").getPath() + location);
			prop.load(is);

		} catch (IOException e) {
			e.printStackTrace();
		}

		return prop;
	}
	
	/**
	 * Save the Properties to the file
	 * @param p
	 * @param location
	 * @throws IOException
	 */
	public static void saveProperties(Properties p, String location) throws IOException {
		OutputStream op = new FileOutputStream(PropertiesUtil.class.getClassLoader().getResource("").getPath() + location);
		p.store(op, "");

	}
	
	public static void main(String args[]) {
		Properties p = PropertiesUtil.getProperties("props.conf");
	}
}
